package com.example.intermingle.contrllor;

import com.example.intermingle.dto.JqGridPageDto;
import com.example.intermingle.dto.UserEditDto;
import com.example.intermingle.service.UserService;
import com.example.intermingle.service.pollingService;
import com.example.intermingle.vo.Polling;
import com.example.intermingle.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author 绿松石
 * @version V1.0
 * @Title UserController
 * @Description
 * @date 2021年08月30日 16:32
 * @since V1.0
 */
@RestController
@RequestMapping( "/user" )
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    pollingService pollingService;

    /**
     * 查询所有用户信息
     * @param page 页数
     * @param size 条数
     * @param userId 用户id
     * @param userName 用户名
     * @param userCode 用户账号
     * @return
     */
    @RequestMapping( "/selectAllUser" )
    public JqGridPageDto<User> selectAllUser(Integer page, Integer size, Integer userId, String userName, String userCode){
        return userService.selectAllUser(page,size,userId,userName,userCode);
    }

    /**
     * 添加用户
     * @param userPassword 用户密码
     * @param userName   用户名
     * @param userCode  用户账号
     * @param userImg    用户头像
     * @return
     */
    @RequestMapping("/addUser")
    public JqGridPageDto<User> addUser(String userPassword, String userName, String userCode,String userImg){
        return userService.addUser(userPassword,userName,userCode,userImg);
    }

    /**
     * 修改用户
     * @param userEditDto  用户对象信息
     * @return
     */
    @RequestMapping("/editUser")
    public  JqGridPageDto<User> editUser(@RequestBody UserEditDto userEditDto){
        return  userService.updateUser(userEditDto);
    }

    /**
     * 删除用户
     * @param userId 用户id
     * @return
     */
    @RequestMapping("/delUser")
    public  JqGridPageDto<User> delUser(Integer userId){
        return  userService.delUser(userId);
    }

    /**
     * 导入文件
     * @param request
     * @return
     */
    @RequestMapping("/importUser")
    public JqGridPageDto<User> importUser(HttpServletRequest  request){
        return userService.imporUser(request);
    }


    /**
     * 导出文件
     * @param pages 页数
     * @param sizes 条数
     * @param response
     */
    @RequestMapping("/exportUser")
    public void exportUser( String pages,  String sizes, HttpServletResponse response){
       Integer page=Integer.parseInt(pages);
        Integer size=Integer.parseInt(sizes);
        userService.exportUser(page,size,response);
    }

    /**
     * 查询所有轮询信息
     * @return
     */
    @RequestMapping("/selectAllPolling")
    public JqGridPageDto<Polling> selectAllPolling(){
        return  pollingService.selectAllPolling();
    }
}
